/***************************************************
 @Name :        1196kk0
 @Time :        2025-05-26
 @Email :       2232506563@qq.com
 @Comment :     LED灯初始化与操作
 @FileName :    drivers_LED.c
 @Version :     4.0
****************************************************/

#include "drivers_LED.h"

/***************************************
函数名：led_config
函数功能：对led引脚进行初始化
输入参数：无
输出参数：无
其它 //LED1     PC4     
     //LED2     PC3      
     //LED3     PC13     
     //D2       PF8  
****************************************/
void led_config(void)
{
    //寄存器操作
    // RCC->AHB1ENR |= (0x01 << 5);
    // GPIOF->MODER &= ~(0x03 << (2*8));
    // GPIOF->MODER |= (0x01 << (2*8));
    // GPIOF->PUPDR &= ~(0x03 << (2*8));
    // GPIOF->PUPDR |= (0x01 << (2*8));

    //标准库
	GPIO_InitTypeDef GPIO_InitStruct;
    RCC_AHB1PeriphClockCmd(LED_Clock_1 , ENABLE);
    RCC_AHB1PeriphClockCmd(LED_Clock_2 , ENABLE);
    RCC_AHB1PeriphClockCmd(LED_Clock_3 , ENABLE);
    RCC_AHB1PeriphClockCmd(LED_Clock_D2 , ENABLE);


    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;

    GPIO_InitStruct.GPIO_Pin = LED_Pin_1;
    GPIO_Init(LED_Port_1 , &GPIO_InitStruct);
    GPIO_InitStruct.GPIO_Pin = LED_Pin_2;
    GPIO_Init(LED_Port_2 , &GPIO_InitStruct);
    GPIO_InitStruct.GPIO_Pin = LED_Pin_3;
    GPIO_Init(LED_Port_3 , &GPIO_InitStruct);
    GPIO_InitStruct.GPIO_Pin = LED_Pin_D2;
    GPIO_Init(LED_Port_D2 , &GPIO_InitStruct);

    GPIO_ResetBits(LED_Port_1 , LED_Pin_1);
    GPIO_ResetBits(LED_Port_2 , LED_Pin_2);
    GPIO_ResetBits(LED_Port_3 , LED_Pin_3);
    GPIO_SetBits(LED_Port_D2 , LED_Pin_D2);

}

/***************************************
函数名：LED_ON
函数功能：打开LED
输入参数：被操作LED的ID
输出参数：无
其它 //LED1     PC4     高电平打开
     //LED2     PC3     高电平打开
     //LED3     PC13    高电平打开
     //D2       PF8     低电平打开
****************************************/
void LED_ON(uint8_t LED_id)
{
    switch (LED_id)
    {
    case LED_ID_1:
        GPIO_SetBits(LED_Port_1 , LED_Pin_1);
        break;
    case LED_ID_2:
        GPIO_SetBits(LED_Port_2 , LED_Pin_2);
        break;
    case LED_ID_3:
        GPIO_SetBits(LED_Port_3 , LED_Pin_3);
        break;
    case LED_ID_D2:
        GPIO_ResetBits(LED_Port_D2 , LED_Pin_D2);
        break;
    }
}

/***************************************
函数名：LED_OFF
函数功能：关闭LED
输入参数：被操作LED的ID
输出参数：无
其它 //LED1     PC4     低电平关闭
     //LED2     PC3     低电平关闭
     //LED3     PC13    低电平关闭
     //D2       PF8     高电平关闭
****************************************/
void LED_OFF(uint8_t LED_id)
{
    switch (LED_id)
    {
    case LED_ID_1:
        GPIO_ResetBits(LED_Port_1 , LED_Pin_1);
        break;
    case LED_ID_2:
        GPIO_ResetBits(LED_Port_2 , LED_Pin_2);
        break;
    case LED_ID_3:
        GPIO_ResetBits(LED_Port_3 , LED_Pin_3);
        break;
    case LED_ID_D2:
        GPIO_SetBits(LED_Port_D2 , LED_Pin_D2);
        break;
    }
}

/***************************************
函数名：LED_Toggle
函数功能：切换LED状态
输入参数：被操作LED的ID
输出参数：无
其它 //LED1     PC4    
     //LED2     PC3    
     //LED3     PC13   
     //D2       PF8     
****************************************/
void LED_Toggle(uint8_t LED_id)
{
    switch (LED_id)
    {
    case LED_ID_1:
        GPIO_ToggleBits(LED_Port_1 , LED_Pin_1);
        break;
    case LED_ID_2:
        GPIO_ToggleBits(LED_Port_2 , LED_Pin_2);
        break;
    case LED_ID_3:
        GPIO_ToggleBits(LED_Port_3 , LED_Pin_3);
        break;
    case LED_ID_D2:
        GPIO_ToggleBits(LED_Port_D2 , LED_Pin_D2);
        break;
    }
}


